package com.cv.platform.dal.mapper.collection;

import com.cv.framework.common.pojo.PageResult;
import com.cv.framework.mybatis.core.mapper.BaseMapperX;
import com.cv.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.cv.platform.controller.platform.collection.vo.collection.CvVideoCollectionPageReqVO;
import com.cv.platform.controller.platform.collection.vo.collection.CvVideoCollectionRespVO;
import com.cv.platform.dal.dataobject.collection.CvVideoCollectionDO;
import com.cv.platform.enums.YesOrNoEnum;
import org.apache.ibatis.annotations.Mapper;

/**
 * 视频合集数据层
 *
 * @author Charles_XDXD
 */
@Mapper
public interface CvVideoCollectionMapper extends BaseMapperX<CvVideoCollectionDO> {

    default PageResult<CvVideoCollectionRespVO> selectPage(CvVideoCollectionPageReqVO reqVO, Integer isVisible) {
        MPJLambdaWrapperX<CvVideoCollectionDO> wrapper = new MPJLambdaWrapperX<CvVideoCollectionDO>()
                .selectAll(CvVideoCollectionDO.class)
                .eq(CvVideoCollectionDO::getUserId, reqVO.getUserId())
                .likeIfPresent(CvVideoCollectionDO::getTitle, reqVO.getTitle())
                .orderByDesc(CvVideoCollectionDO::getCreateTime);
        
        if (isVisible.equals(YesOrNoEnum.YES.getCode())) {
            wrapper.eq(CvVideoCollectionDO::getIsVisible, YesOrNoEnum.YES.getCode());
        }

        return selectJoinPage(reqVO, CvVideoCollectionRespVO.class, wrapper);
    }

}
